package keyboardBehaviors;

import javax.media.j3d.Bounds;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.TransformGroup;

import com.sun.j3d.utils.picking.PickResult;
import com.sun.j3d.utils.picking.behaviors.PickMouseBehavior;

public class KeyDeleteBehaviors extends PickMouseBehavior {
	
	private BranchGroup branchToDel = null;
	//private BranchGroup rootBranchGroup = null;
	private TransformGroup rooTransformGroup = null;
	
	DeleteExecuteBehavior delBehavior = null;
	
	public KeyDeleteBehaviors(BranchGroup root, Canvas3D canvas, Bounds bounds) {
		super(canvas, root, bounds);
		//this.rootBranchGroup = root;
		this.delBehavior = new DeleteExecuteBehavior();
		this.delBehavior.setBounds(bounds);
		this.setSchedulingBounds(bounds);
	}
	
	public KeyDeleteBehaviors(TransformGroup trans, BranchGroup root, Canvas3D canvas, Bounds bounds) {
		super(canvas, root, bounds);
		//this.rootBranchGroup = root;
		this.rooTransformGroup = trans;
		this.delBehavior = new DeleteExecuteBehavior();
		this.delBehavior.setBounds(bounds);
		this.setSchedulingBounds(bounds);
		
	}

	@Override
	public void updateScene(int xpos, int ypos) {
		
		
		if (!mevent.isMetaDown() && mevent.isControlDown()){
			//System.out.println("----------");
			pickCanvas.setShapeLocation(xpos, ypos);
		    PickResult pr = pickCanvas.pickClosest();
		    branchToDel = (BranchGroup)pr.getNode(PickResult.BRANCH_GROUP);
		    
		    if((pr != null)&&(branchToDel!= null)){
		    	//System.out.println("******----------");
		    	//delBehavior.setBT(branchToDel, rooTransformGroup);
		    	//delBehavior.wakeUp();
		    	rooTransformGroup.removeChild(branchToDel);
		    	//System.out.println("****************");
		    }
		}
	}

}
